<template>
  <div id="app">
    <van-nav-bar
      title="vue-cli"
      left-text="返回"
      left-arrow
      @click-left="onClickLeft"
    />

    <router-view />

    <van-tabbar v-model="active">
      <van-tabbar-item
        icon="home-o"
        to="/home"
      >首页</van-tabbar-item>
      <van-tabbar-item
        icon="friends-o"
        badge="5"
        to="/friends"
      >朋友</van-tabbar-item>
      <van-tabbar-item
        icon="cart"
        badge="20"
        to="/cart"
      >购物车</van-tabbar-item>
      <van-tabbar-item
        icon="search"
        dot
        to="/search"
      >搜索</van-tabbar-item>
    </van-tabbar>
  </div>
</template>

<script>
export default {
  data: () => ({
    active: 0
  }),
  created() {},
  methods: {
    onClickLeft() {
      if (window.history.length <= 1) {
        this.$router.push({ path: '/' })
        return false
      } else {
        this.$router.go(-1)
      }
    }
  }
}
</script>

<style lang="less" scoped>
</style>
